from django.shortcuts import redirect
from django.http import JsonResponse
# 配置装饰器


#验证用户登陆信息.如果登陆了,则执行后面的代码,如果没有,则不执行
def islogin(fun):
    def inner(request,*args, **kwargs):
        if request.session.get('uid'):

            return fun(request, *args, **kwargs)
        else:
            # 判断是什么请求,如果是ajax请求,则返回json数据
            if request.is_ajax():
                return JsonResponse({'login':2})
            return redirect('/user/login/')
    return inner

# uid = request.session.get('uid','') #默认为0
#
#     if uid:
#         user = UserInfo.objects.get(id=uid)
#         context = {'title':'个人中心', 'user':user}
#         return render(request, 'user/user_center_info.html', context)
#     else:
#         return redirect('/user/login/')